home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 January / PCWorld_2007-01_cd.bin / v cisle / autoit / autoit-v3.2.0.1-setup.exe / Examples / Helpfile / TrayItemGetHandle.au3 < prev    next >
Text File  |  2006-06-17  |  2KB  |  55 lines

  1. #include <Constants.au3>
  2.  
  3. Opt("TrayMenuMode", 1) ; Don't show the default tray context menu
  4.  
  5. Global Const $MIM_APPLYTOSUBMENUS    = 0x80000000
  6. Global Const $MIM_BACKGROUND        = 0x00000002
  7.  
  8. TraySetIcon("shell32.dll", 21)
  9. TraySetToolTip("This is just a small example to show that colored tray menus" & @LF & "are easy possible under Windows 2000 and higher.")
  10.  
  11. $OptionsMenu    = TrayCreateMenu("Options")
  12. $OnTopItem        = TrayCreateItem("Always On Top", $OptionsMenu)
  13. TrayItemSetState(-1, $TRAY_CHECKED)
  14. $RepeatItem        = TrayCreateItem("Repeat Always", $OptionsMenu)
  15. TrayCreateItem("")
  16. $AboutItem        = TrayCreateItem("About")
  17. TrayCreateItem("")
  18. $ExitItem        = TrayCreateItem("Exit Sample")
  19.  
  20. SetMenuColor(0, 0xEEBB99)   ; BGR color value, '0' means the tray context menu handle itself
  21. SetMenuColor($OptionsMenu, 0x66BB99); BGR color value
  22.  
  23. While 1
  24.     $Msg = TrayGetMsg()
  25.  
  26.     Switch $Msg
  27.         Case $ExitItem
  28.             ExitLoop
  29.         
  30.         Case $AboutItem
  31.             Msgbox(64, "About...", "Colored tray menu sample")
  32.     EndSwitch   
  33. WEnd
  34.  
  35. Exit
  36.  
  37.  
  38. ; Apply the color to the menu
  39. Func SetMenuColor($nMenuID, $nColor)
  40.     ; Minimum OS are Windows98 and 2000 
  41.     If @OSVersion = "WIN_95" Or @OSVersion = "WIN_NT4" Then Return
  42.     
  43.     $hMenu  = TrayItemGetHandle($nMenuID) ; Get the internal menu handle
  44.     
  45.     $hBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $nColor)
  46.     $hBrush = $hBrush[0]
  47.         
  48.     Local $stMenuInfo = DllStructCreate("dword;dword;dword;uint;dword;dword;ptr")
  49.     DllStructSetData($stMenuInfo, 1, DllStructGetSize($stMenuInfo))
  50.     DllStructSetData($stMenuInfo, 2, BitOr($MIM_APPLYTOSUBMENUS, $MIM_BACKGROUND))
  51.     DllStructSetData($stMenuInfo, 5, $hBrush)
  52.     
  53.     DllCall("user32.dll", "int", "SetMenuInfo", "hwnd", $hMenu, "ptr", DllStructGetPtr($stMenuInfo))
  54. EndFunc
  55.